<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>密码找回</title>
    <link rel="stylesheet" href="/static/css/bootstrap.css" th:href="@{/css/bootstrap.css}"/>
    <script th:src="@{/js/jquery-3.3.1.js}"></script>
</head>
<body class="container">
<h1>密码找回</h1>
<!--<form name="login" enctype="multipart/form-data" method="post" th:action="@{/user/forgetPassword}"  onsubmit="return check()">-->
<!--    <div>-->
<!--&lt;!&ndash;        <input id="mail" type="text" name="mail"/>&ndash;&gt;-->
<!--&lt;!&ndash;        <input id="code" type="text" name="code"/>&ndash;&gt;-->
<!--        <button style="width:150px;height:25px" type="button" onclick="sendMail()">发送邮箱验证码</button>-->
<!--&lt;!&ndash;        <button style="width:150px;height:25px" type="button" onclick="sendSMS()">发送短信验证码</button>&ndash;&gt;-->

<!--    </div>-->
<!--&lt;!&ndash;    <input type="submit" value="登录" />&ndash;&gt;-->
<!--</form>-->
<div class="with:80%">
    <form class="form-horizontal" name="verify" enctype="multipart/form-data" th:action="@{/user/toLogin}"  method="post" onsubmit="return check()">
<!--        <div class="form-group">-->
<!--            <label for="username" class="col-sm-2 control-label">用户名</label>-->
<!--            <div class="col-sm-10">-->
<!--                <input type="text" class="form-control" name="username"  id="username" placeholder="Username"/>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label for="mail" class="col-sm-2 control-label" >邮箱号</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="mail" id="mail" placeholder="Mail"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" onclick="sendMail()"class="btn btn-info">发送邮箱验证码</button>
<!--                <input type="submit" value="提交" class="btn btn-info" />-->
<!--                &nbsp; &nbsp; &nbsp;-->
<!--                <input type="reset" value="重置" class="btn btn-info" />-->
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10" >
                <a th:href="@{/user/toLogin}" class="btn btn-info">去登陆</a>
            </div>
        </div>
    </form>

</div>
</body>

<script type="text/javascript">
    var code=null;
    function check() {
        var code1 = verify.code.value;
        alert("check"+code1+":"+code);
        if(code==null){
            return false;
        }
        if(code==code1){
            login.submit();
            return true;
        }else
            return false;
    }
    function sendMail() {
//        alert("sendMail");
        var mail = verify.mail.value;
        $(document).ready(function () {
            $.post("/user/forgetPassword",
                {"mail": mail},
                function (data) {
                    if (data != "") {
                        code=data;
                        alert("sendMail发送成功:"+code);
                    }else
                        alert("sendMail发送失败");

                });
        });
    }
    function sendSMS() {
//        alert("sendSMS");
        var username = login.username.value;
        $(document).ready(function () {
            $.post("/api/sendSMS",
                {"username": username},
                function (data) {
                    /*<![CDATA[*/
                    if (data != null && data!="") {
                        code=data;
                        alert("sendSMS发送成功:"+code);
                    }else
                        alert("sendSMS发送失败");
                    /*]]>*/
                });
        });
    }

</script>
</html>